using System;
using System.Reflection;
using System.Windows.Forms;

namespace XmlObjects
{
	public partial class ObjectPropertyItem : UserControl, IPropertyItem
	{
		private PropertyInfo propertyInfo;
		private object theObject;

		public ObjectPropertyItem(PropertyInfo propertyInfo, object theObject)
		{
			this.propertyInfo = propertyInfo;
			this.theObject = propertyInfo.GetValue(theObject, null);
			if (this.theObject == null)
				this.theObject = Activator.CreateInstance(propertyInfo.PropertyType);
			InitializeComponent();
			label_name.Text = propertyInfo.Name;
			label_type.Text = propertyInfo.PropertyType.FullName;
		}

		private void OnLoad(object sender, EventArgs e)
		{
			throw new NotImplementedException();
		}

		private void button_elipsis_Click(object sender, EventArgs e)
		{
			PropertyPage propertyPage = new PropertyPage(theObject);
			propertyPage.ShowDialog();
		}

		public string PropertyName
		{
			get { return propertyInfo.Name; }
		}

		public Control GetControl()
		{
			return this;
		}

		public object GetValue()
		{
			return theObject;
		}

		public PropertyInfo PropertyInfo
		{
			get { return propertyInfo; }
		}
	}
}